package cn.itsource.service.impl;

import cn.itsource.domain.Article;
import cn.itsource.domain.Comment;
import cn.itsource.repository.CommentRepository;
import cn.itsource.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentRepository repository;


    @Override
    public void add(Comment comment) {
        repository.save(comment);
    }

    @Override
    public void update(Comment comment) {
        repository.save(comment);
    }

    @Override
    public void del(String id) {
        repository.deleteById(id);
    }

    @Override
    public List<Comment> findByArticleId(Long articleId) {
        Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
        return repository.findByArticleId(articleId,sort);
    }
}
